using System.Collections.Generic;
using Platform;
using Platform.CharacterData;
using UnityEngine;
using UnityEngine.UI;
using static Entity;

[CreateAssetMenu(menuName = "skill/SkillDataSO")]
public class SkillDataSO : ScriptableObject
{
    public List<SkillData> skills;

    public void OnEnable()
    {
        // 重置值
        foreach (var skill in skills)
        {
            var fields = typeof(SkillData).GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
            foreach (var field in fields)
            {
                if (System.Attribute.IsDefined(field, typeof(HideInInspector)))
                {
                    switch (field.FieldType.Name)
                    {
                        case "Single": // float
                            field.SetValue(skill, 0f);
                            break;
                        case "Int32": // int
                            field.SetValue(skill, 0);
                            break;
                        case "GameObject":
                        case "Image":
                        case "Transform":
                            field.SetValue(skill, null);
                            break;
                        case "HashSet`1":
                            field.SetValue(skill, new HashSet<Transform>());
                            break;
                        case "List`1":
                            field.SetValue(skill, new List<GameObject>());
                            break;
                        case "Vector3":
                            field.SetValue(skill, Vector3.zero);
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        // foreach (var skill in skills)
        // {
        //     skill.cdRemain = 0;
        //     skill.skillPrefab = null;
        //     skill.attackTargets = new HashSet<Transform>();
        //     skill.combo = 0;
        //     skill.pierced = 0;
        //     skill.backfills.Clear();
        //     skill.targetPos = default;
        // }
    }
}

[System.Serializable]
public class SkillData
{
    [HideInInspector] public GameObject owner;//技能所属的角色
    public int skillId;
    public string name;//技能名称
    public float cooldown;
    [HideInInspector] public float cdRemain;
    public int level;//技能等级
    public int costMp;//法力值消耗
    public float range;
    public float Distance;
    public int attackDamage;
    [Header("攻击间隔")]
    public float attackInterval;//伤害间隔
    [Header("持续时间")]
    public float durationTime;//持续时间

    [Header("攻击类型")]
    public DamageType damageType;

    [Header("攻击目标")]
    public SkillAttackType attackType;//攻击目标

    /// <summary>
    /// 攻击的冻结时间
    /// </summary>
    [Header("冻结时间")]
    public float freezeTime;

    [Header("技能状态")]
    public States[] stateNames;//状态名称

    [Header("技能影响类型")]
    public ImpactEnum[] impactType;//技能影响类型
    [Header("释放范围类型")]
    public SelectorTypeEnum selectorType;//释放范围类型（圆形，扇形，矩形）

    [Header("技能指示器")]
    public SkillIndicatorEnum skillIndicator;//技能指示器名字

    //  public int nextBatterld;//连击的技能ID

    [Header("技能预制体")]
    public string prefabName;//技能预制体名称
    [HideInInspector] public GameObject skillPrefab;//预制体对象

    public LayerMask attackTargetLayers;//能作用的目标Tag
    [HideInInspector] public HashSet<Transform> attackTargets;//作用目标对象数组

    // public string skillIndicator;//技能指示器名字|成功释放技能之前显示出来的辅助技能释放的工具

    [Header("技能图标")]
    public string skillIconName;//技能显示图标名字
    [HideInInspector] public Image skillIcon;//技能事件图标
    [Header("攻击持续类型")]
    public CalculDamageType disappearType;

    //技能生成位置, 处理重复在指定位置生成
    [HideInInspector] public Vector3 targetPos;

    [Header("被动属性")]
    public float chanceActive;

    /// <summary>
    /// 连击技能 处理传送
    /// </summary>
    public SkillEnum nextSkill;

    [Header("远程攻击属性")]
    public Vector2 launchForce;
    public float gravity;

    [Header("多段攻击属性")]
    public int comboCount;
    [HideInInspector] public int combo;
    [Header("穿透属性")]
    public int pierceCount;
    [HideInInspector] public int pierced;


    [Header("装填类技能")]
    public int backfillCount;
    [HideInInspector] public List<GameObject> backfills;


    //给闪电链用的
    [HideInInspector] public Transform lastTarget;

}
